var controlerChat = function(){
	// console.log(mongoose);
	this.user = new require("../models/m_user")();
	this.chat = new require("../models/m_chat")();
};

controlerChat.prototype = {

	LoadHistory : function(ownerId, targetId){
		return chat.LoadHistory(ownerId, targetId, 10);
	},

	NewMessage : function(ownerId, targetId, chatId, ip, time, offine, message){
		this.chat.NewMessage(ownerId, targetId, chatId, ip, time, offine, message);
	},

	NewChat : function(ownerId, targetId){
		this.chat.NewChat(ownerId, targetId);
	},

	Authorization : function(cookieUsername, cookiePassword, cb){
		this.user.AuthorizationNoEncrypt(cookieUsername, cookiePassword, function(err, doc){
			// console.log(err, doc);
			var state = false;
			if(err || !doc /*doc !== undefined*/ ){
			}else{
				state = true;
			}
			// console.log(enable);
			cb('authorized', doc, state);
		});
	},

	AddSocketId : function(_id, socketId, callback){
		this.user.AddSocketId(_id, socketId, callback);
	},

	RemoveSocketId : function(_id, socketId, callback){
		this.user.RemoveSocketId(_id, socketId, callback);
	},

	GetSocketId : function(idChat, callback){
		this.user.GetSocketId(idChat, callback);
	}
};

module.exports = new controlerChat();